window.onload = function(){
		
		function dialog(Option){			
			
			for(var attr in Option){
				this[attr] = Option[attr];
			}
			this.core = new MaoJs();
			
			this.box_id = this.box_id ? this.box_id : "MaoDialog";
			this.box_width = this.box_width ? this.box_width : "600";
			this.box_height = this.box_height ? this.box_height : "400";
			this.box_left = this.box_left ? this.box_left : "300";
			this.box_top = this.box_top ? this.box_top : "50";
			this.box_bgcolor = this.box_bgcolor ? this.box_bgcolor : "red";
			
			this.createBox();
			this.setFixed();
			this.setPosition();
		}
		dialog.prototype = Object.prototype;
		
		dialog.prototype.exist = function(){
			var MaoDialog = document.getElementById(this.box_id);
			if(MaoDialog){
				return true;
			}else{
				return false;
			}
		}
		dialog.prototype.setFixed = function(){
			var brower_version = MaoJs.getVersions();
			if(brower_version[0] != 'IE'){
				this.box_element.css("position","fixed");
			}else{
				
			}
			return brower_version[0];
		}
		dialog.prototype.setPosition = function(){
			
			 var win_width;
			 var win_height;
			 
			 if (window.innerWidth){
				   win_width = window.innerWidth;
			 }else if ((document.body) && (document.body.clientWidth)){
				   win_width = document.body.clientWidth;
			 }
			 
			 if (window.innerHeight){
				   win_height = window.innerHeight;
			 }else if ((document.body) && (document.body.clientHeight)){
				   win_height = document.body.clientHeight;
			 }
			 
			 if (document.documentElement && document.documentElement.clientHeight && document.documentElement.clientWidth)
			   {
					win_height = document.documentElement.clientHeight;
					win_width = document.documentElement.clientWidth;
			   }
			var top = (win_height-this.box_height)/2;
			var left = (win_width-this.box_width)/2;
			
			this.core.css.apply(this.box_element,["top",top]);
			this.core.css.apply(this.box_element, ["left",left]);
		}
		/**
		 * 创建对话框
		 */
		dialog.prototype.createBox = function(){
			
			if(this.exist()){
				alert("已经存在一个id为"+this.box_id+"的窗口,无法再次创建!");
				return;
			}
			var box_element = document.createElement("div");
			this.box_element = box_element;
			
			box_element.setAttribute("id",this.box_id);
			
			// this.core.css.apply(box_element,["width",this.box_width]);
			// this.core.css.apply(box_element, ["height",this.box_height]);
			// this.core.css.apply(box_element, ["background-color",this.box_bgcolor]);
			// this.core.css.apply(box_element, ["display","block"]);
			
			// box_element.style['width'] = "200px";
			// box_element.style['height'] = "200px";
			// box_element.style['backgroundColor'] = "red";
			setcss("width",this.box_width,box_element);
			setcss("height",this.box_height,box_element);
			setcss("background-color",this.box_bgcolor,box_element);
			alert(box_element.style.width);
			var body_element = document.getElementsByTagName('body')[0];
			this.core.getText.apply(box_element,["yuhaya"]);
			body_element.appendChild(box_element);
			
		}
		
		
		var button = document.getElementById('dialog');
		button.onclick = function(){
			// var box_element = document.createElement("div");
			// box_element.style.width = "200px";
			// box_element.style.height = "200px";
			// box_element.style.backgroundColor = "red";
			// var body_element = document.getElementsByTagName('body')[0];
			// body_element.appendChild(box_element);
			var dialogObj = new dialog({
				
				"box_height":"500",
				"box_width":"400",
				"box_top":"50",
				"box_left":"300",
				"box_id":"myDialog"
			});
			// dialogObj.createBox();
		}
	
}



function setcss(attr,val,obj){

	    //设置值
		if(arguments.length>=2){
		  switch (attr) {
		  case "top":
		  case "left":
		  case "width":
		  case "height":
		  obj.style[attr]=val+"px";
		  break;
		  case "opacity":
		  obj.style.filter="alpha(opacity="+val+")";
		  obj.style[attr]=val/100;
	     break;
		 default:
		 obj.style[attr]=val;
		  }
		}
}